<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of Address
 *
 * @author johnnypark
 */
class Model_Address extends Model_Base
{

    protected $_name = 'address';

    public function create($data)
    {
	if (!is_array($data))
	{
	    throw new InvalidArgumentException("Argument is " . gettype($data));
	}

	try
	{
	    $this->db->insert($this->_name, $data);
	} catch (Zend_Db_Statement_Exception $e)
	{
	    throw new InvalidArgumentException("Argument is " . gettype($data) . ". Nested message is: " . $e->getMessage());
	}
    }

    public function lastCreated()
    {
	$lastInsertedId = $this->db->lastInsertId($this->_name);
	return $this->find($lastInsertedId);
    }

    public function find($id)
    {
	$select = $this->db->select()
		->from($this->_name)
		->where('id = ?', $id);
	return $this->db->fetchRow($select);
    }

    public function update(array $address)
    {
	$where = $this->db->quoteInto('id = ?', $address['id']);
	$this->db->update($this->_name, $address, $where);
    }
    public function delete($id)
    {
	$where = $this->db->quoteInto('id = ?', $id);
	$this->db->delete($this->_name, $where);
    }
}

?>
